import Vue from 'vue'
import Vuex from 'vuex'
import Http from '@/common/http'
// import Http from '@/common/http';
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {},
		messageList: [],
		activeMenu: '',

		jumpToInstrumentBitNumber: '',
		jumpToCctvCtype: '',
	},

	mutations: {
		setJumpToCctvCtype(state, provider) {
			state.jumpToCctvCtype = provider;
		},

		clearJumpToCctvCtype(state) {
			state.jumpToCctvCtype = '';
		},


		setJumpToInstrumentBitNumber(state, provider) {
			state.jumpToInstrumentBitNumber = provider;
		},

		clearJumpToInstrumentBitNumber(state) {
			state.jumpToInstrumentBitNumber = '';
		},

		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: provider
			})

			// Http.setToken(provider.token);
			console.log('store:user');
			console.log(state.userInfo);
		},

		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			Http.token = 'default_token';
			uni.removeStorage({
				key: 'userInfo'
			})
			uni.removeStorage({
				key: 'msgList'
			})
		},

		initMessageList(state) {
			console.log('store:initMessageList');
			let localSavedList = uni.getStorageSync('msgList') || [];
			console.log(localSavedList);
			state.messageList = localSavedList;
			console.log(state.messageList);
			console.log('store:initMessageList end');
		},

		addMessage(state, e) {
			console.log('store:addMessage');
			state.messageList.push(e)
			console.log(state.messageList);
			uni.setStorage({
				key: 'msgList',
				data: state.messageList
			})
		},

		clearMessage(state) {
			state.messageList = []
			console.log(state.messageList);
			uni.setStorage({
				key: 'msgList',
				data: state.messageList
			})
		},
	},
	actions: {

	}
})

export default store
